var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1/sch";
var log = require("log4js").getLogger("downloadservice");


MongoClient.connect(url, function (err, db) {
    task = db.collection('task');
    //删除所有
    task.removeMany({}, function (err, result) {
        var testdata = [];
        for (var i = 0; i < 10; i++) {
            var record = {
                name: `iam${i}`,
                wt: [],
                date: new Date()
            }
            //模拟2个时间快
            //以t开头的表示任务ID
            //0开头的表示未安排
            
            record.wt[0] = "t1"
            record.wt[1] = "0"
            
            testdata.push(record)
        }
        task.insert(testdata, function (err, result) {
            //查询 时间块 0 的有任务的记录 
            task.find({ "wt.0": /t(.*)/ }).toArray(function (err, docs) {
                console.log("有安排的" + docs.length);
            })

            //查询 时间块 1 的没有安排的记录
            task.find({ "wt.1": "0" }).toArray(function (err, docs) {
                //console.log("无安排的" + JSON.stringify(docs,"",4));
                console.log("无安排的" + docs.length);
            })

        })

    });


})
